package client.states;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import client.IGameState;
import client.GraphicsLoader;
import client.StateContext;
import client.XMLReader;
import client.commands.ICommand;

import com.jpemartin.jgt.KeyboardStatus;

public class CreditsScreen implements IGameState {
	int scrollY = 350;
	HashMap<String, String> credits;
	
	public CreditsScreen() {
		XMLReader reader = new XMLReader();
		String creditsPath = "Credits.xml";
		credits = reader.readCredits(creditsPath);
	}

	@Override
	public void paint(Graphics g, StateContext stateContext, int GameTime) {
		g.setColor(Color.WHITE);
		g.fillRect(0, 0, 400, 400);
		g.setColor(Color.BLACK);
		Iterator<?> creditsIterator = credits.entrySet().iterator();
		int y = 50;
		while (creditsIterator.hasNext()) {
			@SuppressWarnings("unchecked")
			Map.Entry<String, String> pairs = (Map.Entry<String, String>) creditsIterator
					.next();
			g.setFont(GraphicsLoader.getLargeFont());
			g.drawString(pairs.getKey(), 100, y+scrollY);
			y += 20;
			g.setFont(GraphicsLoader.getSmallFont());
			g.drawString(pairs.getValue(), 100, y+scrollY);
			y += 25;
		}
		scrollY--;
		g.setColor(Color.BLACK);
		g.fillRect(0, 350, 400, 50);
		g.setColor(Color.WHITE);
		g.drawString("Press Enter to return to Main Menu", 100, 375);
	}

	@Override
	public void processKeyHit(StateContext stateContext, KeyboardStatus status) {
		if(status.key[KeyEvent.VK_ENTER]){
			status.key[KeyEvent.VK_ENTER]=false;
			stateContext.setState(new TitleScreen());
		}
	}

}
